<template>
  <view>
    <view class="home_tab">
      <!-- 标题 开始 -->
      <view class="home_tab_title">
        <!-- 分段器 开始 -->
        <view class="title_inner">
          <uni-segmented-control
            :current="current"
            :values="items.map((v) => v.title)"
            @clickItem="onClickItem"
            style-type="text"
            active-color="#d4237a"
          >
          </uni-segmented-control>
        </view>
        <!-- 分段器 结束 -->
        <!-- 搜索按钮 -->
        <view class="iconfont iconsearch"></view>
      </view>
      <!-- 标题 结束 -->

      <!-- 内容 开始 -->
      <view class="home_tab_content">
        <view v-if="current === 0">
          <homeRecommend></homeRecommend>
        </view>
        <view v-if="current === 1">
          <homeCategory></homeCategory>
        </view>
        <view v-if="current === 2">
          <homeNew></homeNew>
        </view>
        <view v-if="current === 3">
          <homeAlbum></homeAlbum>
        </view>
      </view>
      <!-- 内容 结束 -->
    </view>
  </view>
</template>

<script>
import homeRecommend from './home-recommend';
import homeCategory from './home-category';
import homeNew from './home-new';
import homeAlbum from './home-album';
import { uniSegmentedControl } from '@dcloudio/uni-ui';

export default {
  data() {
    return {
      // 分段器
      items: [
        { title: '推荐' },
        { title: '分类' },
        { title: '最新' },
        { title: '专辑' }
      ],
      current: 0
    };
  },
  components: {
    homeRecommend,
    homeCategory,
    homeNew,
    homeAlbum,
    uniSegmentedControl
  },
  methods: {
    onClickItem(e) {
      if (this.current !== e.currentIndex) {
        this.current = e.currentIndex;
      }
    }
  }
};
</script>

<style lang="scss">
.home_tab {
  .home_tab_title {
    position: relative;
    // 分段器
    .title_inner {
      width: 60%;
      margin: 0 auto;
    }
    .iconsearch {
      position: absolute;
      top: 50%;
      transform: translateY(-50%);
      right: 5%;
    }
  }
  .home_tab_content {
  }
}
</style>
